# include <stdio.h>
# include <conio.h>
# include <string.h>
# include <map>
# include "node.h"
# include "node.cpp"
# include "Huffman.h"

int main ()
{
    const int ARRAY_SIZE = 256;
    //const char text[] = "qwertyuiopasdfghjklzxcvbnm";
    const int CASES_NUM = 5;
    const char texts[CASES_NUM][ARRAY_SIZE] = 
                                   {"azaz zatralil lalka azaza lalka zatralil",
                                    "just a simple text with different letters",
                                    "aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbb",
                                    "qwertyuiopasdfghjklzxcvbnm",
                                    "89169749248492057694029459602847602387"};

    char coded[ARRAY_SIZE] = {};
    char uncoded[ARRAY_SIZE] = {};

    for (int i = 0; i < CASES_NUM; i++)
    {
        Node<Entry>* tree = buildHuffmanTree (texts[i]);

        int originalSize = strlen (texts[i]);
        int compressedSize = code (tree, texts[i], coded, originalSize);
        decode (tree, coded, uncoded, compressedSize);
        printf ("Non-compressed:%d\nHfmnCompressed:%d\n%s\n\n", originalSize*8,
                                                                compressedSize,
                                                                uncoded);
        memset (uncoded, 0, ARRAY_SIZE);
        delete tree;
    }
    
    getch ();
}
